package com.jhs.kjs.handler;

import java.io.IOException;
import java.util.Iterator;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

public class LoginFailureHandler implements AuthenticationFailureHandler {
	public void onAuthenticationFailure(HttpServletRequest request,
			HttpServletResponse response, AuthenticationException auth)
			throws IOException, ServletException {
		System.out.println("fail");
		System.out.println("fail");
		System.out.println("fail");
		System.out.println("fail");
		System.out.println("fail");
		System.out.println("fail");
		System.out.println("fail");
		System.out.println("fail");
		System.out.println("fail");
		System.out.println("fail");
		System.out.println("fail");
		System.out.println("fail");
		System.out.println("fail");
		System.out.println("fail");
		System.out.println("fail");
//		
		StringBuilder sb = new StringBuilder();
		String key="";
		Iterator it = request.getParameterMap().keySet().iterator();
		while(it.hasNext()){
			key = it.next().toString();
			sb.append("key [").append(key).append("]");
			sb.append(" : value = ").append(request.getParameter(key).toString()).append("\n");
		}
		sb.append("================================================\n");
		System.out.println(sb.toString());
//		
		HttpSession session = request.getSession();
		session.setAttribute("j_username",request.getParameter("j_username").toString());
		session.setAttribute("msg","아이디와 비밀번호를 확인해주세요.");
		response.sendRedirect(request.getContextPath() + "/user/loginFail");
	}
}